<template>
  <div id="createAddEdit">
    <el-dialog
      title="创建编号"
      width="550px"
      :visible.sync="dialogReachData.isShow"
      :before-close="labelHandleClose"
    >
      <el-form ref="addFormEl" :model="form" :rules="formRules">
        <el-form-item label="编号名称" label-width="90px" prop="reachUser">
          <el-input v-model="form.reachUser" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="编号描述" label-width="90px" prop="content">
          <el-input
            v-model="form.content"
            type="textarea"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <div class="list">
          <div class="title">
            <h3 style="margin-left: 6px">
              添加用户
            </h3>
          </div>
        </div>
        <el-form-item style="margin-top:15px">
          <el-radio
            v-for="item in orderList"
            :key="item.value"
            v-model="form.radio"
            :label="item.value"
          >
            {{ item.label }}
          </el-radio>
        </el-form-item>
        <el-form-item v-if="form.radio === '1'" label="输入大鹏号" prop="dp">
          <el-input
            v-model="form.dp"
            placeholder="请输入大棚号,用逗号隔开"
          ></el-input>
        </el-form-item>
        <el-form-item v-if="form.radio === '2'" label="批量导入" prop="batch">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
          >
            <el-button size="small" type="warning" plain>
              选择文件
            </el-button>
            <!-- <div slot="tip">(说明：大棚号从上到下排序)<em>下载模板</em></div> -->
            <div slot="tip" class="el-upload__tip">
              (说明：大棚号从上到下排序)
              <el-link :underline="false" type="primary">
                下载模板
              </el-link>
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="success" plain @click="cancelLabel">
          取 消
        </el-button>
        <el-button type="success" @click.prevent="handelAdd">
          确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'ReachAddEdit',
  msg: '创建活动-预置用户规则-弹窗',
  props: ['dialogReachData'],
  data() {
    return {
      isAdd: true, // 新增-true,编辑-false
      loading: true,
      // 表单数据
      form: {
        date: '', // 时间
        reachUser: '', // 编号名称
        radio: '1', // 添加用户
        dp: '', // 大棚号
        batch: '' // 批量导入
      },
      orderList: [
        {
          value: '1',
          label: '手动添加'
        },
        {
          value: '2',
          label: '批量导入'
        }
      ],
      formRules: {
        reachUser: [
          { required: true, message: '请输入编号名称', trigger: 'blur' },
          { max: 30, message: '长度在30个字符', trigger: 'blur' }
        ],
        order: [{ required: true, message: '请输入显示顺序', trigger: 'blur' }],
        content: [{ required: true, message: '请输入', trigger: 'blur' }],
        dp: [
          {
            required: true,
            message: '请输入大棚号,用逗号隔开',
            trigger: 'blur'
          }
        ],
        batch: [{ required: true, message: '请选择文件', trigger: 'blur' }]
      }
    }
  },
  mounted() {
    // this.isAdd = this.dialogReachData.type === 'add' ? true : false
    // if (this.dialogReachData.type === 'edit') {
    //   this.form = Object.assign({}, this.dialogReachData.params)
    // }
  },
  methods: {
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.loading = false
      this.dialogReachData.isShow = false
    },
    handelAdd() {
      this.$refs.addFormEl.validate((valid) => {
        if (!valid) {
          return
        }
        this.dialogReachData.isShow = false
        this.$emit('addEdit-success')
      })
    }
  }
}
</script>
<style lang="less">
#createAddEdit {
  .el-dialog {
    border-radius: 4px;
    .el-dialog__header {
      border-bottom: 1px solid rgba(225, 228, 233, 1);
    }
  }
  .list {
    margin-top: 15px;
  }
  .title {
    border-left: 3px solid #1dc8a4;
    height: 12px;
    line-height: 12px;
  }
  .el-upload {
    text-align: left;
    display: block;
    margin-left: 25px;
  }
}
</style>
